<template>
  <div id="setting">
    <van-nav-bar title="设置" left-text="返回" left-arrow @click-left="onClickLeft" />
    <van-cell title="修改密码" @click="goPwd" is-link />
    <van-cell-group>
      <van-cell title="软件版本" @click="versions" value="1.0" is-link />
    </van-cell-group>
    <van-button style="position: fixed;bottom:0;" type="info" size="large" @click="esc">退出登陆</van-button>
  </div>
</template>
<script>
import { Dialog } from "vant";
import { quit } from "@/API/user.js";
import { Toast } from "vant";
export default {
  data() {
    return {};
  },
  methods: {
    onClickLeft() {
      this.$router.go(-1);
    },
    goPwd() {
      this.$router.push("/amendpassword");
    },
    esc() {
      Dialog.confirm({
        message: "确认退出吗？"
      })
        .then(() => {
          quit()
            .then(res => {
              this.$store.commit("updateLogin", false);
              this.$store.commit("updateToken", "");
              this.$store.commit("updateUsername", "");
              this.$store.commit(
                "updateImgUrl",
                "https://www.17sucai.com/preview/1527619/2019-02-21/my/images/user-logo-004.png"
              );
              this.$router.push("/login");
            })
            .catch(err => {
              Dialog({message:"网络错误，请重试"})
            });
        })
        .catch(() => {
          // on cancel
        });
    },
    versions() {
      Toast({
        duration: 1000,
        message: "已是最新版本"
      });
    }
  }
};
</script>
<style lang="less" scoped>
#setting {
  .van-nav-bar__arrow,
  .van-nav-bar__text {
    color: #1989fa;
  }
}
</style>